//
//  TheinquiryViewController.m
//  WE
//
//  Created by 要帅气的生活 on 15/11/20.
//  Copyright © 2015年 UNOHACHA. All rights reserved.
//

#import "TheinquiryViewController.h"
#import "ThesearchView.h"
#import "Size.h"
#import "BaseView.h"
#import <SDCycleScrollView.h>
#import "TheinquiryView.h"
#import "ToolUtil.h"
#import "MoreAdviViewController.h"
#import "AuthenticateControl.h"
#import "DoctorViewController.h"
#import "ShufflingFigureDetailsViewController.h"
@interface TheinquiryViewController ()<SDCycleScrollViewDelegate,UISearchBarDelegate>

{
    UISearchBar *searchBar1;
    //BaseView *view;
}

@property (nonatomic, strong)UIVisualEffectView *views;
@property (nonatomic, strong)UIScrollView * scrollView;
@end



@implementation TheinquiryViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.title = @"咨询";
    
    [self buttonthree];
    [self gundong];
    [self zuihou];
    [self searchbar];
}
- (void)viewWillAppear:(BOOL)animated
{
    self.navigationController.navigationBar.hidden = NO;
    
}

-(void)searchbar{
    
    [ToolUtil createLine:99 superView:self.view lift:0 width:WindowWidth hight:1 color:GRAYCOLOR];
    [ToolUtil createVerticalLine:100 superView:self.view lift:WindowWidth/2 height:WindowWidth/2];
    [ToolUtil createLine:100 + WindowWidth/4 superView:self.view lift:WindowWidth/2 width:WindowWidth/2 hight:1 color:GRAYCOLOR];
    
    searchBar1 = [[UISearchBar alloc] initWithFrame:CGRectMake(1, 66.5, WindowWidth - 2, 30)];
   // searchBar1.barStyle = UIBarStyleDefault;
    searchBar1.placeholder = @"搜索医院,医生,科室,疾病";
    searchBar1.delegate = self;
    [self.view addSubview:searchBar1];
    searchBar1.searchBarStyle = UISearchBarStyleMinimal; //选择样式
    
    _views = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
    _views.frame = CGRectMake(0, 20, WindowWidth, WindowHeight - 20);
    UITapGestureRecognizer *doubleClick = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(pressCancle)];
    doubleClick.numberOfTapsRequired = 1;
    [_views addGestureRecognizer:doubleClick];
    _views.hidden = YES;
    
    UIButton *cancelButton = [UIButton buttonWithType:UIButtonTypeSystem];
    cancelButton.frame = CGRectMake(WindowWidth - 60, 20, 50, 40);
    cancelButton.backgroundColor = [UIColor whiteColor];
    [cancelButton setTitle:@"取消" forState:UIControlStateNormal];
    [cancelButton addTarget:self action:@selector(pressCancle) forControlEvents:UIControlEventTouchUpInside];
    [_views addSubview:cancelButton];
    
    [self.view addSubview:_views];
    
}

- (void)pressCancle{
    searchBar1.frame = CGRectMake(5, 66.5, WindowWidth - 10, 30*Height);
    [self.view addSubview:searchBar1];
    _views.hidden = YES;
    self.navigationController.navigationBar.hidden = NO;
    [searchBar1 resignFirstResponder];
    searchBar1.searchBarStyle = UISearchBarStyleMinimal; //选择样式
}

- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar{
    
    self.navigationController.navigationBar.hidden = YES;
    [_views addSubview:searchBar1];
    searchBar.frame = CGRectMake(10, 20, WindowWidth - 70, 40);
    searchBar.searchBarStyle = UISearchBarStyleMinimal; //选择样式
    _views.hidden = NO;
    return YES;
}



-(void)buttonthree{
    for (int i = 0; i<3; i++) {
        BaseView *baseview = [BaseView new];
        if (i == 0) {
            baseview.frame = CGRectMake(0, 64+36, WindowWidth/2-1, WindowWidth/2);
            //baseview.backgroundColor = [UIColor yellowColor];
            UIView *experts = [[UIView alloc] initWithFrame:CGRectMake(baseview.frame.size.width/5, baseview.frame.size.height/3, baseview.frame.size.width/5*3, baseview.frame.size.height/3)];
            [baseview addSubview:experts];
            
            UIImageView *img = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, experts.frame.size.width/4, experts.frame.size.height/5*2)];
            img.image = [UIImage imageNamed:@"iconfont-zhuanjiayisheng"];
            [experts addSubview:img];
            
            UILabel *expertslabel = [[UILabel alloc] initWithFrame:CGRectMake(experts.frame.size.width/4, 0, experts.frame.size.width/4*3, experts.frame.size.height/5*2)];
            [experts addSubview:expertslabel];
            expertslabel.font = [UIFont systemFontOfSize:16];
            expertslabel.textAlignment = 1;
            expertslabel.text = @"专家咨询";
            
            UILabel *shang = [[UILabel alloc] initWithFrame:CGRectMake(0, experts.frame.size.height/5*2, experts.frame.size.width, experts.frame.size.height/5*1.5)];
            [experts addSubview:shang];
            shang.font = [UIFont systemFontOfSize:13];
            shang.textAlignment = 1;
            shang.alpha = 0.5;
            shang.text = @"三甲医院  特邀专家";
            
            UILabel *xia = [[UILabel alloc] initWithFrame:CGRectMake(0, experts.frame.size.height/5*3.5, experts.frame.size.width, experts.frame.size.height/5*1.5)];
            [experts addSubview:xia];
            xia.font = [UIFont systemFontOfSize:13];
            xia.textAlignment = 1;
            xia.alpha = 0.5;
            xia.text = @"对症寻医  放心看病";
        }
        if (i == 1) {
            baseview.frame = CGRectMake(WindowWidth/2 ,100, WindowWidth/2, WindowWidth/4-1);
            //baseview.backgroundColor = [UIColor purpleColor];
            
            UIView *experts = [[UIView alloc] initWithFrame:CGRectMake(baseview.frame.size.width/5, baseview.frame.size.height/4, baseview.frame.size.width/5*3, baseview.frame.size.height/2)];
            [baseview addSubview:experts];
            
            UIImageView *img = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, experts.frame.size.width/4, experts.frame.size.height/2)];
            img.image = [UIImage imageNamed:@"iconfont-f13"];
            [experts addSubview:img];
            
            UILabel *expertslabel = [[UILabel alloc] initWithFrame:CGRectMake(experts.frame.size.width/4, 0, experts.frame.size.width/4*3, experts.frame.size.height/2)];
            [experts addSubview:expertslabel];
            expertslabel.font = [UIFont systemFontOfSize:16];
            expertslabel.textAlignment = 1;
            expertslabel.text = @"今日义诊";
            
            UILabel *shang = [[UILabel alloc] initWithFrame:CGRectMake(0, experts.frame.size.height/2, experts.frame.size.width, experts.frame.size.height/2)];
            [experts addSubview:shang];
            shang.font = [UIFont systemFontOfSize:13];
            shang.textAlignment = 1;
            shang.alpha = 0.5;
            shang.text = @"特邀专家  爱心解答";
            
        }
        if (i == 2) {
            baseview.frame = CGRectMake(WindowWidth/2 ,100 + WindowWidth/4-1, WindowWidth/2, WindowWidth/4);
            //baseview.backgroundColor = [UIColor greenColor];
            
            UIView *experts = [[UIView alloc] initWithFrame:CGRectMake(baseview.frame.size.width/5, baseview.frame.size.height/4, baseview.frame.size.width/5*3, baseview.frame.size.height/2)];
            [baseview addSubview:experts];
            
            UIImageView *img = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, experts.frame.size.width/4, experts.frame.size.height/2)];
            img.image = [UIImage imageNamed:@"iconfont-shangxianjieda"];
            [experts addSubview:img];
            
            UILabel *expertslabel = [[UILabel alloc] initWithFrame:CGRectMake(experts.frame.size.width/4, 0, experts.frame.size.width/4*3, experts.frame.size.height/2)];
            [experts addSubview:expertslabel];
            expertslabel.font = [UIFont systemFontOfSize:16];
            expertslabel.textAlignment = 1;
            expertslabel.text = @"免费咨询";
            
            UILabel *shang = [[UILabel alloc] initWithFrame:CGRectMake(0, experts.frame.size.height/2, experts.frame.size.width, experts.frame.size.height/2)];
            [experts addSubview:shang];
            shang.font = [UIFont systemFontOfSize:13];
            shang.textAlignment = 1;
            shang.alpha = 0.5;
            shang.text = @"身体不适  全科问诊";
        }
        baseview.tag = 290+i;
        [baseview addTarget:self selector:@selector(Theinquirybutton:)];
        
        [self.view addSubview:baseview];
    }
}
-(void)gundong{
    NSArray *images = @[[UIImage imageNamed:@"shouye3"],
                        [UIImage imageNamed:@"shouye4"],
                        ];
    SDCycleScrollView *cycle = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 79+36+WindowWidth/2, WindowWidth, 110*Height) imagesGroup:images];
    cycle.delegate = self;
    cycle.infiniteLoop = YES;
    cycle.pageControlAliment = SDCycleScrollViewPageContolStyleAnimated;
    cycle.autoScrollTimeInterval = 4.0;
    cycle.dotColor = [UIColor blueColor];
    [self.view addSubview:cycle];
}

-(void)zuihou{
    
    UIView *xian = [[UIView alloc] initWithFrame:CGRectMake(0, 64+36+WindowWidth/2, WindowWidth, 15)];
    [self.view addSubview:xian];
    xian.backgroundColor = [UIColor grayColor];
    xian.alpha = 0.5;
    
    UIView *xians = [[UIView alloc] initWithFrame:CGRectMake(0, 79+36+110*Height+WindowWidth/2, WindowWidth, 15)];
    [self.view addSubview:xians];
    xians.backgroundColor = [UIColor grayColor];
    xians.alpha = 0.5;
    
    UIView *titel = [[UIView alloc] initWithFrame:CGRectMake(0, 94+36+110*Height+WindowWidth/2, WindowWidth, 40)];
    titel.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:titel];
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, WindowWidth, 20)];
    [titel addSubview:label];
    label.textAlignment = 0;
    label.text = @"推荐咨询专家";
    label.font = [UIFont systemFontOfSize:15];
    
    self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 134+36+110*Height+WindowWidth/2, WindowWidth, 120)];
    _scrollView.contentSize = CGSizeMake(60*12+10, 0);
    _scrollView.showsHorizontalScrollIndicator = NO;
    //_scrollView.backgroundColor = [UIColor redColor];
    [self.view addSubview:_scrollView];
    
    for (int i = 0; i < 12; i++) {
        TheinquiryView *theinq = [[TheinquiryView alloc] initWithFrame:CGRectMake(i*60+5, 0, 60, 100)];
        [_scrollView addSubview:theinq];
        [theinq addTarget:self selector:@selector(yisheng:)];
        theinq.tag = 120+i;
        theinq.name.text = @"王宁";
        theinq.shanchan.text = @"黄亚克";
    }
}

- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index
{
    NSLog(@"---点击了第%ld张图片", index);
    ShufflingFigureDetailsViewController *shu = [ShufflingFigureDetailsViewController new];
    shu.view.backgroundColor = [UIColor whiteColor];
    [self.navigationController pushViewController:shu animated:YES];
}

-(void)Theinquirybutton:(BaseView *)button{
    NSLog(@"%ld",button.tag);
    if (button.tag == 290) {
        [self.navigationController pushViewController:[[MoreAdviViewController alloc] init] animated:YES];
    }
    else if (button.tag == 291){
        [self.navigationController pushViewController:[[MoreAdviViewController alloc] init] animated:YES];
    }else if (button.tag == 292){
        [self.navigationController pushViewController:[[AuthenticateControl alloc] init] animated:YES];
    }
    //专家,咨询,义诊
    
}
-(void)yisheng:(TheinquiryView *)yisheng{
    NSLog(@"%ld",yisheng.tag);
    [self.navigationController pushViewController:[[DoctorViewController alloc] init] animated:YES];
    //推荐咨询
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)consulting:(UIView *)viewFrame
{
    
}

@end
